# -*- coding:utf-8 -*-
# 导入包
from json import encoder
from bs4.element import Comment
import requests,bs4
import re,json
# 伪装浏览器
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebssKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}
url = 'https://movie.douban.com/subject/32493666'
# 请求
res = requests.get(url, headers=headers)
# 获取html文件
k = bs4.BeautifulSoup(res.text, 'html.parser')
list=[]
#抓取影片信息
id=k.find('div',id='info')
id1=id.find_all('span',class_='pl')
for q in id1:
    dict={}
    if q.next_sibling.next_sibling.text !='':
        dict[q.text]=q.next_sibling.next_sibling.text
        list.append(dict)
    else:
        dict[q.text]=q.next_sibling
        list.append(dict)
#抓取简介
xx=k.find('div',id='link-report').find('span')
xx=xx.text.replace( ' ' , '' )
#抓取演员信息
art=k.find_all('li',class_='celebrity')
for art1 in art:
    #获取演员照片
    img1=art1.find('div',class_='avatar').get('style').replace( 'background-image: url(' , '' ).replace(')','')
    #获取演员名称
    name1=art1.find('span',class_='name').find('a').text
    #获取演员角色
    name2=art1.find('span',class_='role').text
#获取奖项       
win=k.find_all('ul',class_='award')
for win1 in win :
    #获取赛事
    print(win1.find('a').text)
    #获取奖项
    print(win1.find('li').next_sibling.next_sibling.text)
#获取评论
talk=k.find_all('div',class_='comment-item')
# print(talk)
for talk1 in talk:
    #获取评论时间
    if talk1.find('span',class_='comment-time'):
        print(talk1.find('span',class_='comment-time').text.replace( ' ' , '' ).replace( '\n' , '' ))
    #获取评论人
    if talk1.find('span',class_='comment-info'):
        print(talk1.find('span',class_='comment-info').find('a').text)
    #获取评论内容
    if talk1.find('span',class_='short'):
        print(talk1.find('span',class_='short').text)
#获取评分
print(k.find('strong',class_='ll rating_num').text)
#获取评分分配
pen=(k.find_all('span',class_='rating_per'))
for pen1 in pen:
    print(pen1.text)
print(list)
    